package com.ymatou.iapi.listpriceq.testcase;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.listpriceq.service.GetPriceByCatalogIdsTradeIsolationCall;
import com.ymatou.iapi.productprice.parameter.ProductAllPriceBean;
import com.ymatou.iapi.productprice.parameter.ProductPriceBean;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.ProductPriceCallService;

public class Ts_GetPriceByCatalogIdsTradeIsolation {
	private static int newBuyerId = ProductPriceCallService.getNewCustomer();
	private static int oldBuyerId = ProductPriceCallService.getOldCustomer();
	private static GetPriceByCatalogIdsTradeIsolationCall getPriceByCatalogIdsTradeIsolationCall = new GetPriceByCatalogIdsTradeIsolationCall();
	

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("交易隔离查询接口, 根据商品catalogs list查询商品价格");
	}

	@Before
	public void caseUp() {
		
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getPriceByCatalogIdsTradeIsolationCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetPriceByCatalogIdsTradeIsolation_001() {
		Logger.start(true, "非交易隔离,普通新人活动");
		try {

			ProductAllPriceBean productAllPriceBean = ProductPriceCallService.getProdPriceWithActivity_NewBuyerAndNoIsolation();
			
			List<String> catalogs = new ArrayList<>();
			productAllPriceBean.getCatalogAllPriceBeans().forEach(ele->catalogs.add(ele.getCatalogId()));
			
			
			//1 码头新客户 查询结果为活动价格
			ProductPriceBean newProductPrice = ProductPriceCallService.getProductPriceBeanByUserLevel(productAllPriceBean,true,false);
			JSONObject ret = getPriceByCatalogIdsTradeIsolationCall.callAndGetReturnData(newBuyerId, catalogs);
			ProductPriceCallService.checkPriceListByCatalogs(ret, newProductPrice);
			
			
			//2码头老客户查询结果为普通商品价格逻辑
			ProductPriceBean oldProductPrice = ProductPriceCallService.getProductPriceBeanByUserLevelAndIgnoreActivityPrice(productAllPriceBean,false);
			JSONObject ret2 = getPriceByCatalogIdsTradeIsolationCall.callAndGetReturnData(oldBuyerId, catalogs);
			ProductPriceCallService.checkPriceListByCatalogs(ret2, oldProductPrice);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetPriceByCatalogIdsTradeIsolation_002() {
		Logger.start(true, "非交易隔离,非新人活动");
		try {
			ProductAllPriceBean productAllPriceBean = ProductPriceCallService.getProdPriceWithActivity_NoNewBuyerAndNoIsolation();

			List<String> catalogs = new ArrayList<>();
			productAllPriceBean.getCatalogAllPriceBeans().forEach(ele->catalogs.add(ele.getCatalogId()));
			
		
			//1 码头新客户 查询结果为活动价格
			ProductPriceBean newProductPrice = ProductPriceCallService.getProductPriceBeanByUserLevel(productAllPriceBean,true,false);
			JSONObject ret = getPriceByCatalogIdsTradeIsolationCall.callAndGetReturnData(newBuyerId, catalogs);
			ProductPriceCallService.checkPriceListByCatalogs(ret, newProductPrice);
			
			//2码头老客户查询结果为活动价格
			ProductPriceBean oldProductPrice = ProductPriceCallService.getProductPriceBeanByUserLevel(productAllPriceBean,false,false);
			JSONObject ret2 = getPriceByCatalogIdsTradeIsolationCall.callAndGetReturnData(oldBuyerId, catalogs);
			ProductPriceCallService.checkPriceListByCatalogs(ret2, oldProductPrice);
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetPriceByCatalogIdsTradeIsolation_003() {
		Logger.start(true, "交易隔离,新人活动");
		try {

			ProductAllPriceBean productAllPriceBean = ProductPriceCallService.getProdPriceWithActivity_NewBuyerAndIsolation();
			List<String> catalogs = new ArrayList<>();
			productAllPriceBean.getCatalogAllPriceBeans().forEach(ele->catalogs.add(ele.getCatalogId()));
			
			//1 码头新客户 查询结果为活动价格
			ProductPriceBean newProductPrice = ProductPriceCallService.getProductPriceBeanByUserLevel(productAllPriceBean,true,false);
			JSONObject ret = getPriceByCatalogIdsTradeIsolationCall.callAndGetReturnData(newBuyerId, catalogs);
			ProductPriceCallService.checkPriceListByCatalogs(ret, newProductPrice);
			
			//2码头老客户查询结果为普通商品价格
			ProductPriceBean oldProductPrice = ProductPriceCallService.getProductPriceBeanByUserLevelAndIgnoreActivityPrice(productAllPriceBean,false);
			JSONObject ret2 = getPriceByCatalogIdsTradeIsolationCall.callAndGetReturnData(oldBuyerId, catalogs);
			ProductPriceCallService.checkPriceListByCatalogs(ret2, oldProductPrice);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetPriceByCatalogIdsTradeIsolation_004() {
		Logger.start(true, "交易隔离,非新人活动");
		try {

			ProductAllPriceBean productAllPriceBean = ProductPriceCallService.getProdPriceWithActivity_NoNewBuyerAndIsolation();
			List<String> catalogs = new ArrayList<>();
			productAllPriceBean.getCatalogAllPriceBeans().forEach(ele->catalogs.add(ele.getCatalogId()));
			
			//1 码头新客户 查询结果为活动价格
			ProductPriceBean newProductPrice = ProductPriceCallService.getProductPriceBeanByUserLevel(productAllPriceBean,true,false);
			JSONObject ret = getPriceByCatalogIdsTradeIsolationCall.callAndGetReturnData(newBuyerId, catalogs);
			ProductPriceCallService.checkPriceListByCatalogs(ret, newProductPrice);
			
			//2码头老客户查询结果为活动价格
			ProductPriceBean oldProductPrice = ProductPriceCallService.getProductPriceBeanByUserLevel(productAllPriceBean,false,false);
			JSONObject ret2 = getPriceByCatalogIdsTradeIsolationCall.callAndGetReturnData(oldBuyerId, catalogs);
			ProductPriceCallService.checkPriceListByCatalogs(ret2, oldProductPrice);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetPriceByCatalogIdsTradeIsolation_005() {
		Logger.start(true, "普通商品");
		try {

			String productId = ProductPriceCallService.getProductIdWithAllPrice();
			ProductAllPriceBean productAllPriceBean = ProductPriceCallService.getProductAllPrice(productId,0);
			
			List<String> catalogs = new ArrayList<>();
			productAllPriceBean.getCatalogAllPriceBeans().forEach(ele->catalogs.add(ele.getCatalogId()));
		
			//1 码头新客户 查询结果为普通商品价格
			ProductPriceBean newProductPrice = ProductPriceCallService.getProductPriceBeanByUserLevelAndIgnoreActivityPrice(productAllPriceBean,true);
			JSONObject ret = getPriceByCatalogIdsTradeIsolationCall.callAndGetReturnData(newBuyerId, catalogs);
			ProductPriceCallService.checkPriceListByCatalogs(ret, newProductPrice);
			
			
			//2码头老客户查询结果为普通商品价格
			ProductPriceBean oldProductPrice = ProductPriceCallService.getProductPriceBeanByUserLevelAndIgnoreActivityPrice(productAllPriceBean,false);
			JSONObject ret2 = getPriceByCatalogIdsTradeIsolationCall.callAndGetReturnData(oldBuyerId, catalogs);
			ProductPriceCallService.checkPriceListByCatalogs(ret2, oldProductPrice);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	

}
